package com.springboot.jdk.colleciton;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author: zr
 * @date: 2021-09-16
 */
public class CopyOnWriteArrayListDemo {

    public static void main(String[] args) {
        List<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10; i++) {
            if (i == 9) {
                System.out.println("进入断点");
            }
            list.add("string_" + i);
        }
        list.set(0, "新增数据");
        String s = list.get(0);
        System.out.println(s);
        String remove = list.remove(0);
        System.out.println(remove);
        System.out.println(list);

        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
